﻿package hunterCommonlib.ui {
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	/**
	* ...
	* @author Default
	*/
	public class DragPanel extends Panel {
		protected var _eventOn:String
		protected var _eventOff:String
		protected var _dragTarget:Sprite;
		protected var _lockCenter:Boolean
		public function DragPanel() {
			super()
		}
		public function setDragOn(eventOn:String,eventOff:String,target:Sprite=null,lockCenter:Boolean=false):void {
			if (target == null) {
				target = this;
			}
			_eventOn = eventOn;
			_eventOff = eventOff
			_dragTarget = target;
			_lockCenter = lockCenter
			this.addEventListener(_eventOn, dragOnHandler);
			this.addEventListener(_eventOff, dragOffHandler);
		}
		public function setDragOff():void {
			if (_eventOn == null) {
				return;
			}
			this.removeEventListener(_eventOn, dragOnHandler);
			this.removeEventListener(_eventOff, dragOffHandler);
			_eventOn = null;
			_eventOff = null;
		}
		protected function dragOnHandler(e:Event):void {
			_dragTarget.startDrag(_lockCenter);
		}
		protected function dragOffHandler(e:Event):void {
			_dragTarget.stopDrag();
		}
	}
	
}